package org.example;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.naming.Name;

/**
 * @author GuoChunbo
 * @create 2021-03-11 10:46
 * @Description: 类的描述
 */
@Component
public class ConsumService {

    @RabbitListener(queues = "queue_msg")
    public void queueMsgA(String msg) {
        System.out.println("queueMsgA接收到的消息:" + msg);
    }

    @RabbitListener(queues = "queue_msg")
    public void queueMsgB(String msg) {
        System.out.println("queueMsgB接收到的消息:" + msg);
    }


    //发布订阅模式
    //一个消费者对应一个队列
    //多个队列绑定到一个交换机上

    //建立 Queue 和 Exchange 关系 但是不能自动创建
    @RabbitListener(
        bindings = @QueueBinding(
                value = @Queue(value = "test_queue1",durable = "true",autoDelete = "false"),
                exchange = @Exchange(value = "test_exchange",type = ExchangeTypes.FANOUT),
                key = "test_direct"
        )
    )
    public void testQueueA(String msg) {
        System.out.println("testQueueA接收到的消息:" + msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "test_queue2",durable = "true",autoDelete = "false"),
                    exchange = @Exchange(value = "test_exchange",type = ExchangeTypes.FANOUT),
                    key = "test_direct"
            )
    )
    public void testQueueB(String msg) {
        System.out.println("testQueueB接收到的消息:" + msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "test_queue3",durable = "true",autoDelete = "false"),
                    exchange = @Exchange(value = "test_exchange",type = ExchangeTypes.FANOUT),
                    key = "test_direct"
            )
    )
    public void testQueueC(String msg) {
        System.out.println("testQueueC接收到的消息:" + msg);
    }
}
